var bubR=10;

var bubRRD;
var bubRRD_X;
var bubRRD_Y;
var bubRRD_H;
var bubRRD_W;
var bubRRD_R;
var strStyle;
var scLength;
var bubDg;

var halfBCH;
var halfBCW;


var centerY=$("#bubbles").height()/2-($("#bubbles").parent().height()*0.15);
var centerX=$("#bubbles").width()/2-($("#bubbles").parent().width()*0.18);

//var centerY=$("#bubbles").height()/2-80;
//var centerX=$("#bubbles").width()/2-60;

$(document).ready(function() {
	var json = {
    		"id":GetQueryString('id')
    	};
	
	hmProxy('topic/topicWordtoWord', json, function(data, textStatus, jqXHR){
		data = eval("("+data+")");
		if(data && data.ret == 0){
			var list = data.data;
			var scatterResults = new Array()
			if(list[0]){
				scatterResults = list[0].words;	
			}
//			if(list && list.length > 0){
//				for(var i = 0; i < list.length; i++){
//					alert(list[i].topicword);
//					scatterResults[i] = list[i].topicword;
//				}
////				list.forEach(function(obj){
////					alert(obj.topicword);
////					scatterResults[i] = obj.topicword;
////				});
//			}
		}
		
		scLength=scatterResults.length;
		for(i=scLength-1;i>=0;i--){
			if(i>0){
				bubDg=360*(i-1)/(scLength-1);
				bubRRD_R=bubDg+((Math.random()-.5)*0.2*bubR*8);
				bubRRD_W=(Math.random()*bubR+90);
				bubRRD_H=bubRRD_W;
				bubSubRlen=bubRRD_W/2;
				bubRRD_X=centerX-10+Math.cos(bubRRD_R*Math.PI/180)*bubR*12+bubSubRlen;
				bubRRD_Y=centerY-10+Math.sin(bubRRD_R*Math.PI/180)*bubR*12+bubSubRlen;

				strStyle="style='height:" +
					bubRRD_H+"px;width:"+ bubRRD_W +
					"px;top:"+
					bubRRD_Y+"px;left:"+
					bubRRD_X+"px;'";

			}else{

				strStyle="class='bubCenter' style='height:"+
					bubR*17+"px;width:"+ bubR*17 +
					"px;top:"+centerY+"px;left:"+centerX+"px'";
			}
			var str="<span "+strStyle+ ">"+ scatterResults[i].word +"</span>";
			$("#bubbles").append(str);
		}
	});
})
